#ifndef xpack_test_lang_cxx_split
#define xpack_test_lang_cxx_split
#pragma push_macro("xuser")
#undef  xuser
#define xuser mixc::test_lang_cxx_split::inc
#include"test/helper.hpp" // 需要放第一
#include"lang/cxx/split.hpp"
#include"lang/cxx.hpp"
#pragma pop_macro("xuser")

namespace mixc::test_lang_cxx_split{
    xtest("split"){
        #define xgen(i,value,idx,len,...)                       \
            xassert_eq(info.segment_content_of(i), value);      \
            xassert_eq(info.segment_of(i)->index, uxx(idx));    \
            xassert_eq(info.segment_of(i)->length, uxx(len));   \
            xassert_eq(info.segment_of(i)->is_separator, uxx(__VA_ARGS__ + 0) != 0)

        #define xtest_split(str,...)                            \
            inc::c08{str}.split(__VA_ARGS__, [&](inc::c08_split_result const & info)




        // 特殊情况
        xtest_split("", '\0'){
            xassert_eq(info->count_of_segment, 0u);
            xassert_eq(info->count_of_separator, 0u);
        });



        // 所有元素都是分割符的情况
        xtest_split("a", 'a'){
            xassert_eq(info->count_of_segment, 0u);
            xassert_eq(info->count_of_separator, 0u);
        });

        xtest_split("aa", 'a'){
            xassert_eq(info->count_of_segment, 0u);
            xassert_eq(info->count_of_separator, 0u);
        });



        // 分隔符在开始处
        xtest_split("ab", 'a'){
            xassert_eq(info->count_of_segment, 1u);
            xassert_eq(info->count_of_separator, 0u);
            xgen(0, "b", 1, 1);
        });

        xtest_split("abc", 'a'){
            xassert_eq(info->count_of_segment, 1u);
            xassert_eq(info->count_of_separator, 0u);
            xgen(0, "bc", 1, 2);
        });

        xtest_split("aabc", 'a'){
            xassert_eq(info->count_of_segment, 1u);
            xassert_eq(info->count_of_separator, 0u);
            xgen(0, "bc", 2, 2);
        });



        // 分隔符在中间
        xtest_split("bac", 'a'){
            xassert_eq(info->count_of_segment, 2u);
            xassert_eq(info->count_of_separator, 0u);
            xgen(0, "b", 0, 1);
            xgen(1, "c", 2, 1);
        });

        xtest_split("bbac", 'a'){
            xassert_eq(info->count_of_segment, 2u);
            xassert_eq(info->count_of_separator, 0u);
            xgen(0, "bb", 0, 2);
            xgen(1, "c", 3, 1);
        });

        xtest_split("baac", 'a'){
            xassert_eq(info->count_of_segment, 2u);
            xassert_eq(info->count_of_separator, 0u);
            xgen(0, "b", 0, 1);
            xgen(1, "c", 3, 1);
        });

        xtest_split("baxacc", 'a'){
            xassert_eq(info->count_of_segment, 3u);
            xassert_eq(info->count_of_separator, 0u);
            xgen(0, "b", 0, 1);
            xgen(1, "x", 2, 1);
            xgen(2, "cc", 4, 2);
        });



        // 分隔符在末尾
        xtest_split("ba", 'a'){
            xassert_eq(info->count_of_segment, 1u);
            xassert_eq(info->count_of_separator, 0u);
            xgen(0, "b", 0, 1);
        });

        xtest_split("baa", 'a'){
            xassert_eq(info->count_of_segment, 1u);
            xassert_eq(info->count_of_separator, 0u);
            xgen(0, "b", 0, 1);
        });

        xtest_split("baccaa", 'a'){
            xassert_eq(info->count_of_segment, 2u);
            xassert_eq(info->count_of_separator, 0u);
            xgen(0, "b", 0, 1);
            xgen(1, "cc", 2, 2);
        });





        // 字符串类型


        // 特殊情况
        xtest_split("", "\0", inc::keep_separator){
            xassert_eq(info->count_of_segment, 0u);
            xassert_eq(info->count_of_separator, 0u);
        });



        // 所有元素都是分割符的情况
        xtest_split("aA", "aA", inc::keep_separator){
            xassert_eq(info->count_of_segment, 1u);
            xassert_eq(info->count_of_separator, 1u);
            xgen(0, "aA", 0, 2, true);
        });

        xtest_split("aAaA", "aA", inc::keep_separator){
            xassert_eq(info->count_of_segment, 2u);
            xassert_eq(info->count_of_separator, 2u);
            xgen(0, "aA", 0, 2, true);
            xgen(1, "aA", 2, 2, true);
        });



        // 分隔符在开始处
        xtest_split("aAb", "aA", inc::keep_separator){
            xassert_eq(info->count_of_segment, 2u);
            xassert_eq(info->count_of_separator, 1u);
            xgen(0, "aA", 0, 2, true);
            xgen(1, "b", 2, 1);
        });

        xtest_split("aAbc", "aA", inc::keep_separator){
            xassert_eq(info->count_of_segment, 2u);
            xassert_eq(info->count_of_separator, 1u);
            xgen(0, "aA", 0, 2, true);
            xgen(1, "bc", 2, 2);
        });

        xtest_split("aAaAbc", "aA", inc::keep_separator){
            xassert_eq(info->count_of_segment, 3u);
            xassert_eq(info->count_of_separator, 2u);
            xgen(0, "aA", 0, 2, true);
            xgen(1, "aA", 2, 2, true);
            xgen(2, "bc", 4, 2);
        });



        // 分隔符在中间
        xtest_split("baAc", "aA", inc::keep_separator){
            xassert_eq(info->count_of_segment, 3u);
            xassert_eq(info->count_of_separator, 1u);
            xgen(0, "b", 0, 1);
            xgen(1, "aA", 1, 2, true);
            xgen(2, "c", 3, 1);
        });

        xtest_split("bbaAc", "aA", inc::keep_separator){
            xassert_eq(info->count_of_segment, 3u);
            xassert_eq(info->count_of_separator, 1u);
            xgen(0, "bb", 0, 2);
            xgen(1, "aA", 2, 2, true);
            xgen(2, "c", 4, 1);
        });

        xtest_split("baAaAc", "aA", inc::keep_separator){
            xassert_eq(info->count_of_segment, 4u);
            xassert_eq(info->count_of_separator, 2u);
            xgen(0, "b", 0, 1);
            xgen(1, "aA", 1, 2, true);
            xgen(2, "aA", 3, 2, true);
            xgen(3, "c", 5, 1);
        });

        xtest_split("baAxaAcc", "aA", inc::keep_separator){
            xassert_eq(info->count_of_segment, 5u);
            xassert_eq(info->count_of_separator, 2u);
            xgen(0, "b", 0, 1);
            xgen(1, "aA", 1, 2, true);
            xgen(2, "x", 3, 1);
            xgen(3, "aA", 4, 2, true);
            xgen(4, "cc", 6, 2);
        });



        // 分隔符在末尾
        xtest_split("baA", "aA", inc::keep_separator){
            xassert_eq(info->count_of_segment, 2u);
            xassert_eq(info->count_of_separator, 1u);
            xgen(0, "b", 0, 1);
            xgen(1, "aA", 1, 2, true);
        });

        xtest_split("baAaA", "aA", inc::keep_separator){
            xassert_eq(info->count_of_segment, 3u);
            xassert_eq(info->count_of_separator, 2u);
            xgen(0, "b", 0, 1);
            xgen(1, "aA", 1, 2, true);
            xgen(2, "aA", 3, 2, true);
        });

        xtest_split("baAccaAaA", "aA", inc::keep_separator){
            xassert_eq(info->count_of_segment, 5u);
            xassert_eq(info->count_of_separator, 3u);
            xgen(0, "b", 0, 1);
            xgen(1, "aA", 1, 2, true);
            xgen(2, "cc", 3, 2);
            xgen(3, "aA", 5, 2, true);
            xgen(4, "aA", 7, 2, true);
        });



        // 测试 c08 &&
        xtest_split("aA", inc::c08("aA"), inc::keep_separator){
            xassert_eq(info->count_of_segment, 1u);
            xassert_eq(info->count_of_separator, 1u);
            xgen(0, "aA", 0, 2, true);
        });


        // 测试 c08 &
        inc::c08 aA = "aA";

        xtest_split("aA", aA){
            xassert_eq(info->count_of_segment, 0u);
        });





        // 测试字符数组
        xtest_split("", { '\0' }, inc::keep_separator){
            xassert_eq(info->count_of_segment, 0u);
        });

        xtest_split("abcabc", { 'a', 'c' }, inc::keep_separator){
            xassert_eq(info->count_of_segment, 6u);
            xassert_eq(info->count_of_separator, 4u);
            xgen(0, "a", 0, 1, true);
            xgen(1, "b", 1, 1);
            xgen(2, "c", 2, 1, true);
            xgen(3, "a", 3, 1, true);
            xgen(4, "b", 4, 1);
            xgen(5, "c", 5, 1, true);
        });



        #undef  xtest_split
        #undef  xgen
    };
}

#endif
